
var server = require('../../utils/server');
var seat;
Page({
	data: {
		banner: [],
		goods: [],
		bannerHeight: Math.ceil(290.0 / 750.0 * getApp().screenWidth),
    uid:1,//是否显示新用户商品
	},
	showCoupon: function (e) {
		wx.navigateTo({
      url: '/pages/member/couponlist/coupon',
		  success: function(res){
			// success
		  },
		  fail: function() {
			// fail
		  },
		  complete: function() {
			// complete
		  }
		})
	},
	showOrder: function (e) {
		wx.navigateTo({
      url: '/pages/goods/pointShop/index',
		  success: function(res){
			// success
		  },
		  fail: function() {
			// fail
		  },
		  complete: function() {
			// complete
		  }
		})
	},
	showCollect: function (e) {
		wx.navigateTo({
		  url: '../member/collect/collect',
		  success: function(res){
			// success
		  },
		  fail: function() {
			// fail
		  },
		  complete: function() {
			// complete
		  }
		})
	},
	showMine: function (e) {
		wx.switchTab({
			url: "../member/index/index"
		});
	},
	showSeller: function (e) {
    // wx.showToast({
    //   title: '活动暂未开始',
    //   icon:'none'
    // })
    // return;
		wx.navigateTo({
		  url: '/pages/goods/promoteList/index',
		  success: function(res){
			// success
		  },
		  fail: function() {
			// fail
		  },
		  complete: function() {
			// complete
		  }
		})
	},
	search: function (e) {
    wx.navigateTo({
      url: "../search/index"
		});
	},
	showCarts: function (e) {
		wx.switchTab({
			url: "../cart/cart"
		});
	},
	onLoad: function (options) {


		//seat = options.seat;
		//wx.showToast({title:seat+"seat"});
    this.loadBanner();
    //this.loadMainGoods();
    this.getInviteCode(options);
	},
	getInviteCode: function (options) {
		if (options.uid != undefined) {
			wx.showToast({
				title: '来自用户:' + options.uid + '的分享',
				icon: 'success',
				duration: 2000
			})
		}
	},
	loadBanner: function () {

		var that = this;

        server.getJSON("/Index/home",function(res){
var banner = res.data.result.ad;
				var goods = res.data.result.goods;
				var ad = res.data.ad;
				that.setData({
					banner: banner,
					goods: goods,
					ad: ad,
          list: res.data.new_list,
				});
		});

		
		
	},
	loadMainGoods: function () {
		var that = this;
		var query = new AV.Query('Goods');
		query.equalTo('isHot', true);
		query.find().then(function (goodsObjects) {
			that.setData({
				goods: goodsObjects
			});
		});
	},
	onShow:function(){
    var that = this;
    wx.getSetting({
      success(res) {
        if (!res.authSetting['scope.userInfo']) {
          // 已经授权，可以直接调用 getUserInfo 获取头像昵称
          wx.navigateTo({
            url: '/pages/auth/auth',
          })
        } else {
          getApp().isLogin();
        }
      }
    })
    var info = getApp().globalData.userInfo;
    if(info !== null){
      info = info.reg_time;
    }
    if(info !== undefined && info !== null){
      if((info + 60*60*24*30)*1000 < (new Date()).getTime()){
        that.setData({
          uid:0,
        })
      }
    }
	},
	clickBanner: function (e) {
    return;
		var goodsId = e.currentTarget.dataset.goodsId;
		wx.navigateTo({
			url: "../goods/detail/detail?objectId=" + goodsId
		});
	},
	showDetail: function (e) {
		var goodsId = e.currentTarget.dataset.goodsId;
		wx.navigateTo({
			url: "../goods/detail/detail?objectId=" + goodsId
		});
	},
	showCategories: function () {
		// wx.navigateTo({
		// 	url: "../category/category"
		// });
		wx.switchTab({
			url: "../category/category"
		});
	},
	showGroupList: function () {
		wx.navigateTo({
			url: "../goods/grouplist/list"
		});
	},
	onShareAppMessage: function () {
		return {
      title: '东龙商城',
      desc: '东龙商城',
			path: '/pages/index/index'
		}
	}
})